package com.zhunaer.service.impl;

import com.zhunaer.dao.RoomDao;
import com.zhunaer.entity.Room;
import com.zhunaer.service.RoomService;
import java.math.BigDecimal;

public class RoomServiceImpl implements RoomService {
    private RoomDao roomDao;

    @Override
    public Room findById(Integer roomId) {
        return roomDao.findRoomById(roomId);
    }

    @Override
    public int updateStock(Integer roomId, Integer quantity) {
        return roomDao.updateStock(roomId, quantity);
    }

    @Override
    public void reduceStock(Room room, int quantity) {
        if(room.getStock() < quantity) {
            throw new RuntimeException("房型库存不足");
        }
        room.setStock(room.getStock() - quantity);
    }

    @Override
    public Room getRoomById(int roomId) {
        Room room = new Room();
        room.setRoomId(roomId);
        room.setPrice(new BigDecimal("200.0"));
        room.setStock(5);
        return room;
    }
}